<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
	String worker_id = request.getParameter("worker_id") == null ? "" : request.getParameter("worker_id");
	String worker_name = request.getParameter("worker_name") == null ? "" : request.getParameter("worker_name");

%>
<html>
	<head>
		<title>记账支出</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#type_id").combotree({
				url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=11',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$('#table').datagrid({
				title:'记账支出',
				rownumber:true,
				url:'<%=contextPath %>/springMVC/crm/listPageAccountingOut?worker_id=<%=worker_id%>', 
				loadMsg:'正在加载数据，请稍后......',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
	                {field:'ck',checkbox:true},
				    {title:'id',field:'id',hidden:true}
				]],
				columns:[[
					{title:'记账类型',field:'type_name',width:100,align:'center'},
					{title:'金额',field:'money',width:100,align:'center'},
					{title:'记账时间',field:'operation_time',width:100,align:'center'},
					{title:'说明',field:'remark',width:200,align:'center'},
					{title:'编辑',field:'edit',fit:true,width:50,align:'center',formatter:function(value,rowDate,rowIndex){
						return "<input type='button'  style='border:0px #ff0000 solid;width:25px;height:15px;cursor:pointer'class='icon-modify'  onClick='addOrEditAccounting(1,\""+rowDate.id+"\")'/>";
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
			//----end
		});
		function deleteRows(){
			var rows=$('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				$.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/crm/deleteAccounting",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function addOrEditAccounting(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/crm/addOrEditAccounting.jsp?callback=rtCallBack&worker_id=<%=worker_id%>&worker_name=<%=worker_name%>",1000, 800);
			}else{
				openDialogResize("<%=contextPath %>/springViews/crm/addOrEditAccounting.jsp?callback=rtCallBack&worker_id=<%=worker_id%>&worker_name=<%=worker_name%>&id="+id,1000, 800);
			}
		}
		function doSearch()
		{
			var start_time=jQuery('#start_time').datebox('getValue');  
			var end_time=jQuery('#end_time').datebox('getValue'); 
			var searchValue = $('#searchValue').val();
			var type_id = $('#type_id').combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				type_id:type_id,
				start_time:start_time,
				end_time:end_time
				});
		}
	</script>
	<body>
		<div id="table"></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteRows();">删除</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditAccounting(0);">新增</a>
			</div>
			<div align="right">
				分类：<input  id="type_id" name="type_id" class="easyui-combotree">
				开始时间：<input id="start_time" name="start_time" class="easyui-datebox" style="width:100px" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:100px"/>
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="原因"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>